package com.zhanggm.springboot.demo.controller;

import com.github.pagehelper.PageInfo;
import com.zhanggm.springboot.demo.service.UserService;
import com.zhanggm.springboot.demo.pojo.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.sql.DataSource;

@Controller
public class UserController {
    //日志logger
    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private UserService userService;

    /**
     * 分页列表接口
     * @param user
     * @param pageNum
     * @param pageSize
     * @return
     */
    @RequestMapping("getPageInfo")
    public @ResponseBody PageInfo<User> getPageInfo(User user, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize",defaultValue = "1") Integer pageSize){
        return  userService.getPageInfo(user,pageNum,pageSize);
    }
//    @Autowired
//    private DataSource dataSource;

    @RequestMapping("list")
    public String list(User user, @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                               ModelMap modelMap){
        logger.info("list接口：pageNum:{},pageSize:{}",pageNum,pageSize);
        logger.error("list接口：pageNum:{},pageSize:{}",pageNum,pageSize);
        PageInfo<User> pageInfo = userService.getPageInfo(user, pageNum, pageSize);
        modelMap.addAttribute("pageInfo",pageInfo);
//        System.out.println(dataSource.getClass().getName());
//        System.out.println("abc11111");
//        System.out.println(1111111111);
        return  "list";
    }
}
